import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children:[
      {
        path:"/",
        name:"shouye",
        component:()=>import("../views/shouye/index.vue"),
        children:[
          {
            path:"/",
            name:"houtai",
            component:()=>import("../views/shouye/houtai"),
            meta:{
              name:"后台首页",
            }
          },
          {
            path:"/shangpin1",
            name:"shangpin1",
            component:()=>import("../views/shouye/shangpin"),
            meta:{
              name:"商品列表",
            }
          },
          {
            path:"/xiangce",
            name:"xiangce",
            component:()=>import("../views/shouye/xiangce"),
            meta:{
              name:"相册管理",
            }
          }
        ]
      },
      {
        path:"/dingdan",
        name:"dingdan",
        component:()=>import("../views/dingdan/index.vue")
      },
      {
        path:"/huiyuan",
        name:"huiyuan",
        component:()=>import("../views/huiyuan/index.vue")
      },
      {
        path:"/shangpin",
        name:"shangpin",
        component:()=>import("../views/shangpin/index.vue"),
        children:[
          {
            path:"/shangpin4",
            name:"shangpin4",
            component:()=>import("../views/shangpin/shangpin1")
          },
          {
            path:"/shangpin2",
            name:"shangpin2",
            component:()=>import("../views/shangpin/shangpin2")
          },
          {
            path:"/shangpin3",
            name:"shangpin3",
            component:()=>import("../views/shangpin/shangpin3")
          }
        ]
      },
      {
        path:"/shezhi",
        name:"shezhi",
        component:()=>import("../views/shezhi/index.vue")
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component:()=>import("../views/Login")
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

import {Message} from "element-ui";
router.beforeEach((to,from,next)=>{
  if(localStorage.getItem("token")){
    next();
  }else{
    if(to.path == "/login"){
      next();
    }else{
      Message("请先登录用户信息")
      next("/login");
    }
  }
})

export default router
